'''
Created on 14 de Nov de 2011

@author: 33120 37176
'''

import pygame
from pygame.locals import *

GRID_SIZE = (11,11)     #patches
PATCH_SIZE = (32,18)    #pixels/patch

w = GRID_SIZE[0] * PATCH_SIZE[0]
h = GRID_SIZE[1] * PATCH_SIZE[1]

pygame.init()
SCREEN = pygame.display.set_mode((w,h))

clock = pygame.time.Clock()
color1 = (255,0,0)
color2 = (0,255,0)
#SCREEN.fill((200,200,200))

x1 = 3
x2 = 0

v1 = 1.5 #patches/segundo
v2 = 2.5

while True:
    for event in pygame.event.get():
        print event
        if event.type == QUIT:
            exit()
    
    time_passed = clock.tick(70)
    print time_passed        
    SCREEN.fill((200,200,200))
            
    pos = (x1,x1)            
    r = Rect(pos[0]*PATCH_SIZE[0],pos[1]*PATCH_SIZE[1],PATCH_SIZE[0],PATCH_SIZE[1])
    pygame.draw.rect(SCREEN,color1,r,0)
    
    pos = (x2,x2)            
    r = Rect(pos[0]*PATCH_SIZE[0],pos[1]*PATCH_SIZE[1],PATCH_SIZE[0],PATCH_SIZE[1])
    pygame.draw.rect(SCREEN,color2,r,0)
    
    x1 = (x1 + v1*time_passed/1000.) % GRID_SIZE[0]
    x2 = (x2 + v2*time_passed/1000.) % GRID_SIZE[0]
    #print x
    
    pygame.display.flip()
    
